﻿using EFModel;
using IServices;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;

namespace Serives
{
    public class Teengage_resume: Iengage_resume
    {
        private readonly MyDBContext he;

        public Teengage_resume(MyDBContext he)
        {
            this.he = he;
        }
        //国籍查询
        public Task<string> Gj()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "国籍").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //民族查询
        public Task<string> Mz()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "民族").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //宗教信仰查询
        public Task<string> Zjxy()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "宗教信仰").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //政治面貌查询
        public Task<string> Zzmm()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "政治面貌").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //教育年限查询
        public Task<string> Jynx()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "教育年限").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //学历查询
        public Task<string> Xl()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "学历").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //专业查询
        public Task<string> Zy()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "专业").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //特长查询
        public Task<string> Tc()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "特长").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //爱好查询
        public Task<string> Ah()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "爱好").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
        //简历登记添加
        public Task<int> Insert(engage_resume resume)
        {
            return Task.Run(() =>
            {
                he.engage_resume.Add(resume);
                int num= he.SaveChanges();
                return num;
            });
        }
        //简历登记表未推荐查询
        public Task<ResultInfo> Query(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.interview_status == 0);
                var list = he.engage_resume                              
                    .Where(e=> e.interview_status == 0)
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //简历登记表未推荐模糊查询
        public Task<ResultInfo> Like(engage_resume resume, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.human_major_name == resume.human_major_name &&
                    e.human_major_kind_name == resume.human_major_kind_name &&
                    e.regist_time >= resume.regist_time &&
                    e.regist_time <= resume.pass_regist_time &&
                    e.interview_status == 0 &&
                    (e.human_name.Contains(resume.human_name) ||
                    e.human_telephone.Contains(resume.human_telephone) ||
                    e.human_idcard.Contains(resume.human_idcard) ||
                    e.human_history_records.Contains(resume.human_history_records))
                    );
                var list = he.engage_resume 
                    .Where(e => e.human_major_name == resume.human_major_name &&
                    e.human_major_kind_name == resume.human_major_kind_name &&
                    e.regist_time>=resume.regist_time &&
                    e.regist_time<=resume.pass_regist_time &&  
                    e.interview_status == 0 &&
                    (e.human_name.Contains(resume.human_name) ||
                    e.human_telephone.Contains(resume.human_telephone) ||
                    e.human_idcard.Contains(resume.human_idcard) ||
                    e.human_history_records.Contains(resume.human_history_records)))
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                   
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //简历登记表已推荐模糊查询
        public Task<ResultInfo> LikeTo(engage_resume resume, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.human_major_name == resume.human_major_name &&
                    e.human_major_kind_name == resume.human_major_kind_name &&
                    e.regist_time >= resume.regist_time &&
                    e.regist_time <= resume.pass_regist_time &&
                    (e.interview_status == 1 || e.interview_status == 10) &&
                    (e.human_name.Contains(resume.human_name) ||
                    e.human_telephone.Contains(resume.human_telephone) ||
                    e.human_idcard.Contains(resume.human_idcard) ||
                    e.human_history_records.Contains(resume.human_history_records))
                    );
                var list = he.engage_resume  
                    .Where(e => e.human_major_name == resume.human_major_name &&
                    e.human_major_kind_name == resume.human_major_kind_name &&
                    e.regist_time >= resume.regist_time &&
                    e.regist_time <= resume.pass_regist_time &&
                    (e.interview_status == 1 || e.interview_status == 10) &&
                    (e.human_name.Contains(resume.human_name) ||
                    e.human_telephone.Contains(resume.human_telephone) ||
                    e.human_idcard.Contains(resume.human_idcard) ||
                    e.human_history_records.Contains(resume.human_history_records)))
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //简历登记表已推荐查询
        public Task<ResultInfo> QueryTo(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.interview_status == 1|| e.interview_status == 10);
                var list = he.engage_resume 
                    .Where(e => e.interview_status == 1 || e.interview_status == 10)
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //职位申请到简历登记的回显查询
        public Task<engage_major_release> Cx(int id)
        {
            return Task.Run(() => {
                return he.engage_major_release.Find(id);
            });
        }
        //简历表回显
        public Task<engage_resume> Jlcx(int id)
        {
            return Task.Run(() => {
                return he.engage_resume.Find(id);
            });
        }
        //简历登记表修改,推荐
        public Task<int> Upda(engage_resume release)
        {
            return Task.Run(() => {
                engage_resume ite=he.engage_resume.Find(release.res_id);
                ite.human_major_kind_id = release.human_major_kind_id;
                ite.human_major_id = release.human_major_id;
                ite.human_major_kind_name = release.human_major_kind_name;
                ite.human_major_name = release.human_major_name;
                ite.engage_type = release.engage_type;
                ite.human_name = release.human_name;
                ite.human_sex = release.human_sex;
                ite.human_picture = release.human_picture;
                ite.human_email = release.human_email;
                ite.human_telephone = release.human_telephone;
                ite.human_homephone = release.human_homephone;
                ite.human_mobilephone = release.human_mobilephone;
                ite.human_address = release.human_address;
                ite.human_postcode = release.human_postcode;
                ite.human_nationality = release.human_nationality;
                ite.human_birthplace = release.human_birthplace;
                ite.human_birthday = release.human_birthday;
                ite.human_race = release.human_race;
                ite.human_party = release.human_party;
                ite.human_idcard = release.human_idcard;
                ite.human_age = release.human_age;
                ite.human_college = release.human_college;
                ite.human_educated_degree = release.human_educated_degree;
                ite.human_educated_years = release.human_educated_years;
                ite.human_educated_major = release.human_educated_major;
                ite.demand_salary_standard = release.demand_salary_standard;
                ite.human_specility = release.human_specility;
                ite.human_hobby = release.human_hobby;                       
                ite.human_history_records = release.human_history_records;
                ite.human_religion = release.human_religion;
                ite.remark = release.remark;
                ite.recomandation = release.recomandation;
                ite.interview_status = release.interview_status;
                ite.checker = release.checker;
                ite.check_time = release.check_time;
                int num = he.SaveChanges();
                return num;
            });
        }
        //简历登记表已录用分页查询
        public Task<ResultInfo> QuqerLy(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.interview_status == 4&& e.pass_checkComment == null);
                var list = he.engage_resume
                    .Where(e => e.interview_status == 4 && e.pass_checkComment == null)
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //面试登记录用查询
        public Task<string> JlcxTo(int id)
        {
            return Task.Run(() =>
            {
                return JsonConvert.SerializeObject(he.engage_interview.Where(e => e.resume_id == id));
            });
        }
        //简历登记录用申请审核意见修改
        public Task<int> Shyj(engage_resume _Resume)
        {
            return Task.Run(() =>
            {
                engage_resume engage_ = he.engage_resume.Find(_Resume.res_id);
                engage_.pass_checkComment = _Resume.pass_checkComment;
                int num = he.SaveChanges();
                return num;
            });
        }
        //简历登记录用审批查询
        public Task<ResultInfo> QuqerSp(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.interview_status == 4 && e.pass_checkComment == "通过"&&e.pass_passComment==null);
                var list = he.engage_resume
                    .Where(e => e.interview_status == 4 && e.pass_checkComment == "通过" && e.pass_passComment == null)
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //简历登记录用申请审批意见修改
        public Task<int> Shysp(engage_resume _Resume)
        {
            return Task.Run(() =>
            {
                engage_resume engage_ = he.engage_resume.Find(_Resume.res_id);
                engage_.pass_passComment = _Resume.pass_passComment;
                int num = he.SaveChanges();
                return num;
            });
        }
        //简历录用通过查询
        public Task<ResultInfo> Lycx(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.pass_passComment=="通过"&&e.pass_checkComment=="通过");
                var list = he.engage_resume
                    .Where(e => e.pass_passComment == "通过" && e.pass_checkComment == "通过")
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //职称查询
        public Task<string> zc()
        {
            return Task.Run(() =>
            {
                var nv = he.config_public_char.Where(e => e.attribute_kind == "职称").ToList();
                return JsonConvert.SerializeObject(nv);
            });
        }
    }
}
